@extends('shared.adminBase')
@section('title','消息列表')
@section('content')
    <section class="content-header">
        <h1>消息列表</h1>
        <ol class="breadcrumb">
            <li><a href="{{URL::action('AdminController@innerIndex')}}"><i class="fa fa-home"></i> 首页</a></li>
            <li class="active">消息列表</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box">
                    <div class="box-header"></div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                            <form id="form1" action="{{URL::action('GameController@getBroadcastList')}}"
                                  method="get">
                                <input type="hidden" name="page" value="{{$pagerSet->currentPage()}}">
                                <div class="row" style="margin-left: 5px;">
                                    <label>玩家ID：<input class="form-control" name="userID"
                                                       value="{{$form->userID}}"></label>
                                    <label>类型：
                                        <select name="type" class="form-control">
                                            <option value="">全部</option>
                                            @foreach(App\Framework\Enum\BroadcastTypeEnum::$dataMap as $k=>$v)
                                                @if($k==$form->type)
                                                    <option value="{{$k}}" selected="selected">{{$v}}</option>
                                                @else
                                                    <option value="{{$k}}">{{$v}}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </label>
                                    <label>发送时间:</label>
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" name="startDate" value="{{$form->startDate}}"
                                               class="form-control pull-right" id="startDate">
                                    </div>
                                    <span>-</span>
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" name="endDate" value="{{$form->endDate}}"
                                               class="form-control pull-right" id="endDate">
                                    </div>
                                    <button type="submit" class="btn btn-primary">查询</button>
                                    <button type="button" onclick="clearForm('form1');" class="btn btn-primary">清空
                                    </button>
                                </div>
                            </form>
                            <br/>
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="example1" class="table table-bordered table-striped dataTable"
                                           role="grid" aria-describedby="example1_info">
                                        <thead>
                                        <tr role="row">
                                            <th>编号</th>
                                            <th>类型</th>
                                            <th>玩家ID</th>
                                            <th>消息内容</th>
                                            <th>发送时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($pagerSet as $item)
                                            <tr role="row" class="odd">
                                                <td>{{$item->broadcast_id}}</td>
                                                <td>{{App\Framework\Enum\BroadcastTypeEnum::getName($item->type)}}</td>
                                                <td>{{$item->user_id}}</td>
                                                <td>{{$item->content}}</td>
                                                <td>{{$item->send_date}}</td>
                                                <td>
                                                    <a href="javascript:del('{{$item->broadcast_id}}');"
                                                       class="btn-xs btn-default">删除</a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </table>
                                </div>
                            </div>
                            <div class="row">
                                @include('shared.tablePaginate')
                            </div>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@endsection


<script type="text/javascript">

    //单个删除
    function del(id) {
        if (confirm('确定要删除该条站内信吗？') == false) {
            return;
        }

        $.post('{{URL::action('GameController@deleteBroadcast')}}', {
            'id': id,
            '_token': '{{csrf_token()}}'
        }, function (result) {

            if (result.success) {
                alert('删除成功');
                window.location.reload();
            }
            else {
                alert(result.info);
            }
        });
    }

</script>
